﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TicTacToe
{
    public class Player
    {
        private const int xpos = 3;
        private const int ypos = 3;

        public bool CheckValidInput(string s, char[,] m)
        { 
            if ( (s.Contains(',')) && (s.Length==3) )
            {
                string[] values = s.Split(',');
                int x = int.Parse(values[0]);
                int y = int.Parse(values[1]);

                if ((x < 3) && (x >= 0) && (y < 3) && (y >= 0) && (m[x, y] != 'X') && (m[x, y] != 'O'))
                {
                    m[x, y] = 'X';
                    Console.WriteLine("Ja fint");
                    return true;
                }
                else
                    return false;
            }
            else
                return false;
        } //end checkvalidinput

       

        public bool Player_1(char[,] m)
        {
            // return value false=quit true = played.

            bool quit = false;
            bool validinput = false;
            bool humanplayer = false;

            while ((!validinput) && (!quit) )
            {
                Console.Write("Player 1 Put in postition  X,Y  e.g 1,2 --> ");
                string s = Console.ReadLine();

                if (s.Contains('q'))
                    quit = true;
                else
                {
                    validinput = CheckValidInput(s,m);
                    if (validinput)
                    {
                        humanplayer = true;
                    }
                    else
                        Console.WriteLine("Invalid move, try again !!! please type in x,y 0 to 2, eq 0,0  (q for quit) ");

                }
            } //end while

            return humanplayer;
        }
    }
}
